<?php

/**
 * 横幅管理
 * @author  Mr.L <349865361@qq.com>
 */

namespace app\site\admin;

class BannerAdmin extends \app\system\admin\SystemExtendAdmin {

    protected $_model = 'SiteBanner';

    /**
     * 模块信息
     */
    protected function _infoModule() {
        return [
            'info' => [
                'name' => '图片管理',
                'description' => '管理站点中的横幅图片',
            ],
            'fun' => [
                'index' => true,
                'add' => true,
                'edit' => true,
                'del' => true,
            ]
        ];
    }

    public function _indexParam() {
        return [
            'class_id' => 'class_id',
            'keyword' => 'title'
        ];
    }

    public function _indexOrder() {
        return 'sort asc, banner_id asc';
    }

    public function _indexWhere($whereMaps) {
        if(!$whereMaps['class_id']) {
            $contestList = target('site/SiteBannerClass')->loadList();
            if(empty($contestList)) {
                $this->error('请先添加横幅!');
            }
            $whereMaps['class_id'] = $contestList[0]['class_id'];
        }
        return $whereMaps;
    }

    public function _indexPage() {
        return 100;
    }

    public function _indexAssign($pageMaps) {
        $classList = target('site/SiteBannerClass')->loadList();
        $id = $pageMaps['class_id'];
        if(empty($id)) {
            $id = $classList[0]['class_id'];
        }

        return array(
            'classList' => $classList,
            'classId' => $id
        );
    }

    protected function _addAssign() {
        $classId = request('get', 'class_id', 1);
        return array(
            'classInfo' => target('site/SiteBannerClass')->getInfo($classId),
            'classId' => $classId
        );
    }

    protected function _editAssign($info) {
        return array(
            'classInfo' => target('site/SiteBannerClass')->getInfo($info['class_id']),
            'classId' => $info['class_id']
        );
    }

    public function _indexUrl($id) {
        return url('index', array('class_id' => request('post', 'class_id')));
    }

}